/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Tuan Nguyen
 */
@Entity
@Table(name = "ContactPerson")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ContactPerson.findAll", query = "SELECT c FROM ContactPerson c"),
    @NamedQuery(name = "ContactPerson.findByContactPersonID", query = "SELECT c FROM ContactPerson c WHERE c.contactPersonID = :contactPersonID"),
    @NamedQuery(name = "ContactPerson.findByName", query = "SELECT c FROM ContactPerson c WHERE c.name = :name"),
    @NamedQuery(name = "ContactPerson.findByMobile", query = "SELECT c FROM ContactPerson c WHERE c.mobile = :mobile"),
    @NamedQuery(name = "ContactPerson.findByEmail", query = "SELECT c FROM ContactPerson c WHERE c.email = :email")})
public class ContactPerson implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ContactPersonID")
    private Integer contactPersonID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "Name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "Mobile")
    private String mobile;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 100)
    @Column(name = "Email")
    private String email;
    @OneToMany(mappedBy = "contactPersonID")
    private Collection<RealEstate> realEstateCollection;

    public ContactPerson() {
    }

    public ContactPerson(Integer contactPersonID) {
        this.contactPersonID = contactPersonID;
    }

    public ContactPerson(Integer contactPersonID, String name, String mobile) {
        this.contactPersonID = contactPersonID;
        this.name = name;
        this.mobile = mobile;
    }

    public Integer getContactPersonID() {
        return contactPersonID;
    }

    public void setContactPersonID(Integer contactPersonID) {
        this.contactPersonID = contactPersonID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @XmlTransient
    public Collection<RealEstate> getRealEstateCollection() {
        return realEstateCollection;
    }

    public void setRealEstateCollection(Collection<RealEstate> realEstateCollection) {
        this.realEstateCollection = realEstateCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contactPersonID != null ? contactPersonID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ContactPerson)) {
            return false;
        }
        ContactPerson other = (ContactPerson) object;
        if ((this.contactPersonID == null && other.contactPersonID != null) || (this.contactPersonID != null && !this.contactPersonID.equals(other.contactPersonID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return " " + name + " ";
    }
    
}
